package com.nhjf.mobile.controller.userinformation;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.JobDetailAwareTrigger;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.util.WebUtils;

import com.nhjf.command.comment.OperationCommand;
import com.nhjf.common.page.Pagination;
import com.nhjf.mobile.common.util.SysProperties;
import com.nhjf.model.cn_nojd.Cnnojd;
import com.nhjf.model.student.Student;
import com.nhjf.model.system.AdminSession;
import com.nhjf.model.system.User;
import com.nhjf.model.teachers.Courses;
import com.nhjf.model.teachers.OrganizationHasStudent;
import com.nhjf.model.teachers.ReviewPainting;
import com.nhjf.model.teachers.Teacher;
import com.nhjf.model.teachers.UserFollow;
import com.nhjf.pojo.dto.cn_nojd.PersonaldetailsDto;
import com.nhjf.pojo.dto.painting.MypaintingDto;
import com.nhjf.pojo.dto.result.ServiceResultDto;
import com.nhjf.pojo.dto.result.userResultDto;
import com.nhjf.pojo.dto.reviewPainting.PersonalinformationDto;
import com.nhjf.pojo.dto.reviewPainting.RepaintinglistDto;
import com.nhjf.pojo.dto.reviewPainting.reviewPaintingResultDto;
import com.nhjf.pojo.qo.Personalinformation.PersonalinformationQo;
import com.nhjf.pojo.qo.cn_nojd.CnnojdQo;
import com.nhjf.pojo.qo.jobDetails.JobDetailsQo;
import com.nhjf.pojo.qo.studnet.StudentQo;
import com.nhjf.pojo.qo.system.AdminSessionQo;
import com.nhjf.pojo.qo.system.UserQo;
import com.nhjf.pojo.qo.teachers.OrganizationHasStudentQo;
import com.nhjf.pojo.qo.teachers.ReviewPaintingQo;
import com.nhjf.pojo.qo.teachers.TeachersQo;
import com.nhjf.pojo.qo.teachers.UserFollowQo;
import com.nhjf.service.cn_nojd.CnnojdService;
import com.nhjf.service.jobDetails.JobDetailsService;
import com.nhjf.service.student.StudentService;
import com.nhjf.service.system.AdminSessionService;
import com.nhjf.service.system.UserService;
import com.nhjf.service.teachers.OrganizationHasStudentService;
import com.nhjf.service.teachers.ReviewPaintingService;
import com.nhjf.service.teachers.TeachersService;
import com.nhjf.service.teachers.UserFollowService;

import net.sf.json.JSONObject;
@Controller
@RequestMapping("/Uinformation")
public class UserinformationController {

	@Autowired
	private StudentService studentService;
	@Autowired
	private TeachersService teachersService;
	@Autowired
	private AdminSessionService adminSessionService;
	@Autowired
	private UserService userService;
	@Autowired
	private ReviewPaintingService reviewPaintingService;
	@Autowired
	private UserFollowService userFollowService;
	@Autowired
	private CnnojdService cnnojdService;
	@Autowired
	private OrganizationHasStudentService organizationHasStudentService;
	@Autowired
	private JobDetailsService  jobDetailsService;


	/**
	 * 前台-我的概述
	 * @param request
	 * @param response
	 * @param model
	 * @param token
	 * @param adminSessionQo
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/information_View")
	public String view(HttpServletRequest request, HttpServletResponse response, Model model,
			@RequestParam(value="token", required=true)String  token ) {
		String code  =  "500";
		Map<String, Object> resMap=new HashMap<String, Object>();
		userResultDto userDto=new userResultDto();
		try {
			AdminSessionQo adminSessionQo=new AdminSessionQo();
			adminSessionQo.setToken(token);
			AdminSession adminSession=adminSessionService.queryUnique(adminSessionQo);
			if(adminSession==null) {
				resMap.put("code", "406");
				resMap.put("message", "不存在此账号！");
				return JSONObject.fromObject(resMap).toString();
			}else {
				adminSession.getLoginName();
				UserQo userQo=new UserQo();
				userQo.setUserName(adminSession.getLoginName());
				User user= userService.queryUnique(userQo);
				if(user==null) {
					resMap.put("code", "406");
					resMap.put("message", "未登录!");
					return JSONObject.fromObject(resMap).toString();
				}else {
					userDto.setUserId(user.getId());

					//					if(user.getIsRole()==1 ||  user.getIsRole()==3) {
					//						TeachersQo teachersQo=new TeachersQo();
					//						teachersQo.setUserId(user.getId());
					//						Teacher teacher= teachersService.queryUnique(teachersQo);
					//						if(teacher.getUser()!=null) {
					//							teacher.getUser().setUserPassword("");
					//						}
					//
					//						ReviewPaintingQo reviewPaintingQo=new ReviewPaintingQo();
					//						reviewPaintingQo.setTeacherId(teacher.getId());
					//						reviewPaintingQo.setTypeOne(2L);
					//						Integer reviewPainting= reviewPaintingService.queryCount(reviewPaintingQo);
					//						reviewPaintingQo.setTypeOne(3L);
					//						Integer reviewPainting1= reviewPaintingService.queryCount(reviewPaintingQo);
					//						reviewPaintingQo.setTypeOne(4L);
					//						Integer reviewPainting2= reviewPaintingService.queryCount(reviewPaintingQo);
					//						reviewPaintingQo.setTypeOne(5L);
					//						Integer reviewPainting3= reviewPaintingService.queryCount(reviewPaintingQo);
					//						userDto.setIdentification(1);
					//						userDto.setTeacherId(teacher.getId());
					//						//查询老师粉丝的数量
					//						UserFollowQo userFollowQo=new UserFollowQo();
					//						userFollowQo.setFollowUserId(user.getId());
					//						Integer teacherFs= userFollowService.queryCount(userFollowQo);
					//
					//
					//						//查询老师关注的数量
					//						UserFollowQo userFollowQo1=new UserFollowQo();
					//						userFollowQo1.setFansUserId(user.getId());
					//						Integer gteacher= userFollowService.queryCount(userFollowQo1);
					//						SysProperties sysProperties=SysProperties.getInstance();
					//						String imagePath=sysProperties.get("imagePath");
					//						userDto.setAvatar(imagePath+"/picture/"+teacher.getAvatar());
					//						userDto.setFollowUserId(gteacher);
					//						userDto.setFansUserId(teacherFs);
					//						userDto.setColor(reviewPainting);
					//						userDto.setPrimeDrawing(reviewPainting1);
					//						userDto.setSketch(reviewPainting2);
					//						userDto.setDesign(reviewPainting3);
					//						userDto.setName(teacher.getNickname());
					//						
					//						System.out.println(teacher.getName());
					//						resMap.put("code", "200");
					//						resMap.put("message", userDto);
					//						return JSONObject.fromObject(resMap).toString();
					//					}else {
					UserQo userQo1=new UserQo();
					userQo1.setUserId(user.getId());
					User user1=userService.queryUnique(userQo1);
					if(user1!=null) {
						ReviewPaintingQo reviewPaintingQo=new ReviewPaintingQo();
						reviewPaintingQo.setSeachUser(true);
						reviewPaintingQo.setSeachTeacher(true);
						reviewPaintingQo.setUserId(user1.getId());
						reviewPaintingQo.setTypeOne(2L);
						Integer reviewPainting= reviewPaintingService.queryCount(reviewPaintingQo);
						reviewPaintingQo.setTypeOne(3L);
						Integer reviewPainting1= reviewPaintingService.queryCount(reviewPaintingQo);
						reviewPaintingQo.setTypeOne(4L);
						Integer reviewPainting2= reviewPaintingService.queryCount(reviewPaintingQo);
						reviewPaintingQo.setTypeOne(70L);
						Integer reviewPainting3= reviewPaintingService.queryCount(reviewPaintingQo);
						reviewPaintingQo.setTypeOne(5L);
						Integer reviewPainting4= reviewPaintingService.queryCount(reviewPaintingQo);
						userDto.setIdentification(2);
						//查询学生粉丝的数量
						UserFollowQo userFollowQo=new UserFollowQo();
						userFollowQo.setFollowUserId(user.getId());
						Integer studentFs= userFollowService.queryCount(userFollowQo);

						//查询学生关注的数量
						UserFollowQo userFollowQo1=new UserFollowQo();
						userFollowQo1.setFansUserId(user.getId());
						Integer gstudent= userFollowService.queryCount(userFollowQo1);
						SysProperties sysProperties=SysProperties.getInstance();
						String imagePath=sysProperties.get("imagePath");
						StudentQo studentqo=new StudentQo();
						studentqo.setUserid(user1.getId());
						Student student= studentService.queryUnique(studentqo);
						TeachersQo teachersQo=new TeachersQo();
						teachersQo.setSeachUser(true);
						teachersQo.setSeachOrganization(true);
						teachersQo.setUserId(user1.getId());
						Teacher teacher= teachersService.queryUnique(teachersQo);
						if(student!=null) {
							userDto.setAvatar(imagePath+"/picture/"+student.getAvatar());
							userDto.setName(student.getNickname());
							JobDetailsQo detailsQo=new JobDetailsQo();
							detailsQo.setSeachPostJob(true);
							detailsQo.setSeachStudent(true);
							detailsQo.setStudentId(student.getId());
							detailsQo.setStatus(2);
							detailsQo.setUnpaidReason(0);
							Integer count= jobDetailsService.queryCount(detailsQo);
							userDto.setUnpaidWorkCount(count);
						}
						else {
							userDto.setAvatar(imagePath+"/picture/"+teacher.getAvatar());
							userDto.setName(teacher.getNickname());
						}

						userDto.setFollowUserId(gstudent);
						userDto.setFansUserId(studentFs);
						userDto.setColor(reviewPainting);
						userDto.setPrimeDrawing(reviewPainting1);
						userDto.setSketch(reviewPainting2);
						userDto.setDesign(reviewPainting3);
						userDto.setPureArt(reviewPainting4);

						resMap.put("code", "200");
						resMap.put("message", userDto);
						return JSONObject.fromObject(resMap).toString();
					}
				}


			}
			//			}
			resMap.put("code", "500");
			resMap.put("message", "没有此老师或学生！");
			return JSONObject.fromObject(resMap).toString();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			resMap.put("code", "500");
			resMap.put("message", "系统异常！");
			return JSONObject.fromObject(resMap).toString();

		}

	}
	@RequestMapping("/studentList")
	@ResponseBody
	public String studentList(@RequestParam(value="token", required=true)String token,@RequestParam(value = "page", defaultValue = "1")Integer page) {
		Map<String, Object> resMap=new HashMap<String, Object>();

		AdminSessionQo adminSessionQo=new AdminSessionQo();
		adminSessionQo.setToken(token);
		AdminSession adminSession=adminSessionService.queryUnique(adminSessionQo);
		if(adminSession==null) {
			resMap.put("code", "406");
			resMap.put("message", "不存在此账号！");
			return JSONObject.fromObject(resMap).toString();
		}else {
			UserQo userQo=new UserQo();
			userQo.setUserName(adminSession.getLoginName());
			User user= userService.queryUnique(userQo);
			if(user==null) {
				resMap.put("code", "406");
				resMap.put("message", "未登录!");
				return JSONObject.fromObject(resMap).toString();
			}else {
				TeachersQo qo=new TeachersQo();
				qo.setSeachUser(true);
				qo.setUserId(user.getId());
				qo.setSeachOrganization(true);
				Teacher teacher= teachersService.queryUnique(qo);
				if(teacher==null){
					resMap.put("code", "406");
					resMap.put("message", "未登录!");
					return JSONObject.fromObject(resMap).toString();
				}else{
					OrganizationHasStudentQo hasStudentQo=new OrganizationHasStudentQo();
					hasStudentQo.setOrganizationId(teacher.getTraininginstitution().getId());
					Pagination pagination = new Pagination();
					pagination.setPageSize(50);
					pagination.setPageNo(page);
					pagination.setCondition(hasStudentQo);
					pagination = organizationHasStudentService.queryPagination(pagination);

					List<OrganizationHasStudent> list=(List<OrganizationHasStudent>)pagination.getList();
					SysProperties sysProperties=SysProperties.getInstance();
					String imagePath=sysProperties.get("imagePath");
					for (OrganizationHasStudent organizationHasStudent : list) {

						organizationHasStudent.getStudent().setAvatar(imagePath+"/picture/"+organizationHasStudent.getStudent().getAvatar());
					}
					resMap.put("code", "200");
					resMap.put("message", pagination);
					return JSONObject.fromObject(resMap).toString();
				}


			}
		}



	}
	/**
	 * 老师段改画
	 * @param request
	 * @param response
	 * @param model
	 * @param token
	 * @param adminSessionQo
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/teacherReviewPainting")
	public String teacherReviewPainting(HttpServletRequest request, HttpServletResponse response, Model model,
			@RequestParam(value="token", required=true)String  token ) {
		String code  =  "500";
		Map<String, Object> resMap=new HashMap<String, Object>();
		userResultDto userDto=new userResultDto();
		try {
			AdminSessionQo adminSessionQo=new AdminSessionQo();
			adminSessionQo.setToken(token);
			AdminSession adminSession=adminSessionService.queryUnique(adminSessionQo);
			if(adminSession==null) {
				resMap.put("code", "406");
				resMap.put("message", "不存在此账号！");
				return JSONObject.fromObject(resMap).toString();
			}else {
				adminSession.getLoginName();
				UserQo userQo=new UserQo();
				userQo.setUserName(adminSession.getLoginName());
				User user= userService.queryUnique(userQo);
				if(user==null) {
					resMap.put("code", "406");
					resMap.put("message", "未登录!");
					return JSONObject.fromObject(resMap).toString();
				}else {
					userDto.setUserId(user.getId());

					if(user.getIsRole()==1 ||  user.getIsRole()==3) {
						TeachersQo teachersQo=new TeachersQo();
						teachersQo.setUserId(user.getId());
						Teacher teacher= teachersService.queryUnique(teachersQo);
						if(teacher.getUser()!=null) {
							teacher.getUser().setUserPassword("");
						}

						ReviewPaintingQo reviewPaintingQo=new ReviewPaintingQo();
						reviewPaintingQo.setTeacherId(teacher.getId());
						reviewPaintingQo.setTypeOne(2L);
						reviewPaintingQo.setStatus(1);
						Integer reviewPainting= reviewPaintingService.queryCount(reviewPaintingQo);
						reviewPaintingQo.setTypeOne(3L);
						Integer reviewPainting1= reviewPaintingService.queryCount(reviewPaintingQo);
						reviewPaintingQo.setTypeOne(4L);
						Integer reviewPainting2= reviewPaintingService.queryCount(reviewPaintingQo);
						reviewPaintingQo.setTypeOne(70L);
						Integer reviewPainting3= reviewPaintingService.queryCount(reviewPaintingQo);
						reviewPaintingQo.setTypeOne(5L);
						Integer reviewPainting4= reviewPaintingService.queryCount(reviewPaintingQo);
						userDto.setIdentification(1);
						userDto.setTeacherId(teacher.getId());

						userDto.setStayColor(reviewPainting);
						userDto.setStayPrimeDrawing(reviewPainting1);
						userDto.setStaySketch(reviewPainting2);
						userDto.setStayDesign(reviewPainting3);
						userDto.setStayPureArt(reviewPainting4);

						ReviewPaintingQo reviewPaintingQo1=new ReviewPaintingQo();
						reviewPaintingQo1.setTeacherId(teacher.getId());
						reviewPaintingQo1.setTypeOne(2L);
						reviewPaintingQo1.setStatus(2);
						Integer newreviewPainting= reviewPaintingService.queryCount(reviewPaintingQo1);
						reviewPaintingQo1.setTypeOne(3L);
						Integer newreviewPainting1= reviewPaintingService.queryCount(reviewPaintingQo1);
						reviewPaintingQo1.setTypeOne(4L);
						Integer newreviewPainting2= reviewPaintingService.queryCount(reviewPaintingQo1);
						reviewPaintingQo1.setTypeOne(70L);
						Integer newreviewPainting3= reviewPaintingService.queryCount(reviewPaintingQo1);
						reviewPaintingQo1.setTypeOne(5L);
						Integer newreviewPainting4= reviewPaintingService.queryCount(reviewPaintingQo1);

						userDto.setAlreadyColor(newreviewPainting);
						userDto.setAlreadyPrimeDrawing(newreviewPainting1);
						userDto.setAlreadySketch(newreviewPainting2);
						userDto.setAlreadyDesign(newreviewPainting3);
						userDto.setAlreadyPureArt(newreviewPainting4);

						ReviewPaintingQo reviewPaintingQo2=new ReviewPaintingQo();
						reviewPaintingQo2.setTeacherId(teacher.getId());
						reviewPaintingQo2.setTypeOne(2L);
						reviewPaintingQo2.setIsOrganizationPainting(1);;
						Integer organizationreviewPainting= reviewPaintingService.queryCount(reviewPaintingQo2);
						reviewPaintingQo1.setTypeOne(3L);
						Integer organizationreviewPainting1= reviewPaintingService.queryCount(reviewPaintingQo2);
						reviewPaintingQo1.setTypeOne(4L);
						Integer organizationreviewPainting2= reviewPaintingService.queryCount(reviewPaintingQo2);
						reviewPaintingQo1.setTypeOne(70L);
						Integer organizationreviewPainting3= reviewPaintingService.queryCount(reviewPaintingQo2);
						reviewPaintingQo1.setTypeOne(5L);
						Integer organizationreviewPainting4= reviewPaintingService.queryCount(reviewPaintingQo2);

						userDto.setOrganizationStudentPictuesColor(organizationreviewPainting);
						userDto.setOrganizationStudentPictuesPrimeDrawing(organizationreviewPainting1);
						userDto.setOrganizationStudentPictuesSketch(organizationreviewPainting2);
						userDto.setOrganizationStudentPictuesDesign(organizationreviewPainting3);
						userDto.setOrganizationStudentPictuesPureArt(organizationreviewPainting4);
						SysProperties sysProperties=SysProperties.getInstance();
						String imagePath=sysProperties.get("imagePath");
						userDto.setAvatar(imagePath+"/picture/"+teacher.getAvatar());

						userDto.setName(teacher.getNickname());


						resMap.put("code", "200");
						resMap.put("message", userDto);
						return JSONObject.fromObject(resMap).toString();
					}else {
						resMap.put("code", "500");
						resMap.put("message", "没有此老师！");
					}


				}
			}
			resMap.put("code", "500");
			resMap.put("message", "没有此老师！");
			return JSONObject.fromObject(resMap).toString();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			resMap.put("code", "500");
			resMap.put("message", "系统异常！");
			return JSONObject.fromObject(resMap).toString();

		}

	}


	//查看别人信息
	@ResponseBody
	@RequestMapping("/Myinformation")
	public String myinformation(HttpServletRequest request, HttpServletResponse response, Model model,
			String id ,@RequestParam(value="token", required=false)String  token) {

		PersonaldetailsDto personaldetailsDto=new PersonaldetailsDto();
		personaldetailsDto.setFollowStatus(0);
		Map<String, Object> resMap=new HashMap<String, Object>();
		try {
			SysProperties sysProperties=SysProperties.getInstance();
			String imagePath=sysProperties.get("imagePath");
			UserQo userQo=new UserQo();
			userQo.setUserId(Long.parseLong(id));
			User user= userService.queryUnique(userQo);
			personaldetailsDto.setUserId(user.getId());
			if(StringUtils.isNotEmpty(token)) {

				AdminSessionQo adminSessionQo=new AdminSessionQo();
				adminSessionQo.setToken(token);
				AdminSession adminSession=adminSessionService.queryUnique(adminSessionQo);
				if(adminSession==null) {
					resMap.put("code", "406");
					resMap.put("message", "不存在此账号！");
					return JSONObject.fromObject(resMap).toString();
				}else {
					UserQo userQo1=new UserQo();
					userQo1.setUserName(adminSession.getLoginName());
					User user1= userService.queryUnique(userQo1);
					if(user1!=null) {

						UserFollowQo userFollowQo=new UserFollowQo();
						userFollowQo.setFansUserId(user1.getId());
						userFollowQo.setFollowUserId(user.getId());
						UserFollow userFollow=userFollowService.queryUnique(userFollowQo);
						if(userFollow==null) {
							personaldetailsDto.setFollowStatus(2);
						}else{
							personaldetailsDto.setFollowStatus(1);
						}

					}
				}


			}
			TeachersQo teachersQo=new TeachersQo();
			teachersQo.setSeachOrganization(true);
			teachersQo.setUserId(user.getId());
			Teacher teacher= teachersService.queryUnique(teachersQo);
			if(teacher!=null) {
				//查询老师粉丝的数量
				UserFollowQo userFollowQo=new UserFollowQo();
				userFollowQo.setFollowUserId(user.getId());
				Integer studentFs= userFollowService.queryCount(userFollowQo);
				//查询老师关注的数量
				UserFollowQo userFollowQo1=new UserFollowQo();
				userFollowQo1.setFansUserId(user.getId());
				Integer gstudent= userFollowService.queryCount(userFollowQo1);
				//查询头像 昵称....
				personaldetailsDto.setAvatar(imagePath+"/picture/"+teacher.getAvatar());
				personaldetailsDto.setNickname(teacher.getNickname());
				personaldetailsDto.setFollowUserId(gstudent);
				personaldetailsDto.setFansUserId(studentFs);
				personaldetailsDto.setSelfintroduction(user.getSelfintroduction());
				personaldetailsDto.setTeacherId(teacher.getId());
				personaldetailsDto.setIsRole(2);
				personaldetailsDto.setIsopenAgencyPromotion(teacher.getTraininginstitution().getIsopenAgencyPromotion());
				personaldetailsDto.setComment(teacher.getTraininginstitution().getComment());
//				personaldetailsDto.setDetails(teacher.getTraininginstitution().getDetails());
				personaldetailsDto.setOrgName(teacher.getTraininginstitution().getName());
				Map<String ,String>address=new HashMap<String, String>();
				//省
				if(user.getProvince()!=null) {
					Cnnojd province= cnnojdService.get(user.getProvince());
					address.put("Province", province.getName());
				}else {
					address.put("Province", "");
				}
				if(user.getCity()!=null) {
					Cnnojd Addresscity= cnnojdService.get(user.getCity());
					address.put("City", Addresscity.getpName());
				}else {
					address.put("City", "");
				}

				//区
				if(user.getCounty()!=null) {
					Cnnojd County= cnnojdService.get(user.getCounty());
					address.put("County",County.getpName());
				}else {
					address.put("County", "");
				}
				personaldetailsDto.setAddress(address);
				resMap.put("code", "200");
				resMap.put("message",personaldetailsDto);
				return JSONObject.fromObject(resMap).toString();
			}
			//如果查看的是学生
			StudentQo studentQo=new StudentQo(); 
			studentQo.setUserid(user.getId());
			Student student=studentService.queryUnique(studentQo);
			if(student!=null) {
				//查询学生粉丝的数量
				UserFollowQo userFollowQo=new UserFollowQo();
				userFollowQo.setFollowUserId(user.getId());
				Integer studentFs= userFollowService.queryCount(userFollowQo);

				//查询学生关注的数量
				UserFollowQo userFollowQo1=new UserFollowQo();
				userFollowQo1.setFansUserId(user.getId());
				Integer gstudent= userFollowService.queryCount(userFollowQo1);
				//查询头像 昵称...
				personaldetailsDto.setAvatar(imagePath+"/picture/"+student.getAvatar());
				personaldetailsDto.setNickname(student.getNickname());
				personaldetailsDto.setFollowUserId(gstudent);
				personaldetailsDto.setFansUserId(studentFs);
				personaldetailsDto.setSelfintroduction(user.getSelfintroduction());
				personaldetailsDto.setIsRole(1);
				Map<String ,String>address=new HashMap<String, String>();
				//省
				if(user.getProvince()!=null) {
					Cnnojd province= cnnojdService.get(user.getProvince());
					address.put("Province",province.getName());
				}else {
					address.put("Province", "");
				}
				if(user.getCity()!=null) {
					Cnnojd Addresscity= cnnojdService.get(user.getCity());
					address.put("City", Addresscity.getpName());
				}else {
					address.put("City", "");
				}

				//区
				if(user.getCounty()!=null) {
					Cnnojd County= cnnojdService.get(user.getCounty());
					address.put("County",County.getpName());
				}else {
					address.put("County", "");
				}
				personaldetailsDto.setAddress(address);
				resMap.put("code", "200");
				resMap.put("message", personaldetailsDto);
				return JSONObject.fromObject(resMap).toString();
			}
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			resMap.put("code", "500");
			resMap.put("message", "异常抛出！");
			return JSONObject.fromObject(resMap).toString();
		}
		resMap.put("code", "500");
		resMap.put("message", "信息加载失败！");
		return JSONObject.fromObject(resMap).toString();
	}


	//查看改画详情
	@ResponseBody
	@RequestMapping("/Change_painting")
	public String Changepainting(HttpServletRequest request, HttpServletResponse response, Model model,
			@RequestParam(value="token", required=true)String  token, String id) {
		Map<String, Object> resMap=new HashMap<String, Object>();
		RepaintinglistDto repaintinglistDto=new RepaintinglistDto();
		reviewPaintingResultDto reviewPaintingResultDto=new reviewPaintingResultDto();
		try {
			AdminSessionQo adminSessionQo=new AdminSessionQo();
			adminSessionQo.setToken(token);
			AdminSession adminSession=adminSessionService.queryUnique(adminSessionQo);
			if(adminSession==null) {
				resMap.put("code", "406");
				resMap.put("message", "不存在此账号！");
				return JSONObject.fromObject(resMap).toString();
			}else {
				UserQo userQo=new UserQo();
				userQo.setUserName(adminSession.getLoginName());
				User user= userService.queryUnique(userQo);
				if(user==null) {
					resMap.put("code", "406");
					resMap.put("message", "未登录!");
					return JSONObject.fromObject(resMap).toString();
				}else {
					//老师素描/速写.../
					TeachersQo teachersQo=new TeachersQo();
					teachersQo.setUserId(user.getId());
					Teacher teacher= teachersService.queryUnique(teachersQo);
					if(teacher!=null) {

						ReviewPaintingQo reviewPaintingQo=new ReviewPaintingQo();
						reviewPaintingQo.setTeacherId(teacher.getId());
						reviewPaintingQo.setReviewId(Long.parseLong(id));
						reviewPaintingQo.setSeachUser(true);
						ReviewPainting reviewPainting=reviewPaintingService.queryUnique(reviewPaintingQo);

						SysProperties sysProperties=SysProperties.getInstance();
						String imagePath=sysProperties.get("imagePath");
						StudentQo qo=new StudentQo();
						qo.setSeachStudent(true);
						qo.setUserid(reviewPainting.getUser().getId());
						Student student= studentService.queryUnique(qo);
						if(student!=null&&StringUtils.isNotEmpty(student.getAvatar())) {
							student.setAvatar(imagePath+"/picture/"+student.getAvatar());
							reviewPainting.setAvatar(student.getAvatar());
						}
						if(StringUtils.isNotEmpty(reviewPainting.getChangepaintingURL())){
							reviewPainting.setChangepaintingURL(imagePath+"/reviewPainting/"+reviewPainting.getChangepaintingURL());
						}
						if(StringUtils.isNotEmpty(reviewPainting.getNotchangedURL())){
							reviewPainting.setNotchangedURL(imagePath+"/reviewPainting/"+reviewPainting.getNotchangedURL());
						}
						resMap.put("code", "200");
						resMap.put("message", reviewPainting);
						return JSONObject.fromObject(resMap).toString();
					}
					//学生查看改画
					UserQo userQo1=new UserQo(); 
					userQo1.setUserId(user.getId());
					User user1=userService.queryUnique(userQo1);
					if(user1.getIsRole()==2) {
						ReviewPaintingQo reviewPaintingQo=new ReviewPaintingQo();
						reviewPaintingQo.setSeachUser(true);
						reviewPaintingQo.setUserId(user1.getId());
						reviewPaintingQo.setSeachTeacher(true);
						reviewPaintingQo.setReviewId(Long.parseLong(id));
						//							repaintinglistDto.setReleasetime(reviewPainting.getReleasetime());
						//							repaintinglistDto.setChangepaintingURL(reviewPainting.getChangepaintingURL());
						//							repaintinglistDto.setNotchangedURL(reviewPainting.getNotchangedURL());
						//							repaintinglistDto.setIntroduce(reviewPainting.getIntroduce());
						ReviewPainting reviewPainting=reviewPaintingService.queryUnique(reviewPaintingQo);
						SysProperties sysProperties=SysProperties.getInstance();
						String imagePath=sysProperties.get("imagePath");
						StudentQo qo=new StudentQo();
						qo.setSeachStudent(true);
						qo.setUserid(reviewPainting.getUser().getId());
						Student student= studentService.queryUnique(qo);
						if(!StringUtils.isEmpty(student.getAvatar())) {
							if(student.getAvatar().indexOf(imagePath+"/picture/")>=0) {

							}else {
								student.setAvatar(imagePath+"/picture/"+student.getAvatar());
								reviewPainting.setAvatar(student.getAvatar());
							}
						}
						if(StringUtils.isNotEmpty(reviewPainting.getChangepaintingURL())){
							reviewPainting.setChangepaintingURL(imagePath+"/reviewPainting/"+reviewPainting.getChangepaintingURL());
						}	
						if(StringUtils.isNotEmpty(reviewPainting.getNotchangedURL())){
							reviewPainting.setNotchangedURL(imagePath+"/reviewPainting/"+reviewPainting.getNotchangedURL());
						}
						resMap.put("code", "200");
						resMap.put("message", reviewPainting);
						return JSONObject.fromObject(resMap).toString();
					}else {

						ReviewPaintingQo reviewPaintingQo=new ReviewPaintingQo();
						reviewPaintingQo.setSeachUser(true);
						reviewPaintingQo.setUserId(user1.getId());
						reviewPaintingQo.setSeachTeacher(true);
						reviewPaintingQo.setReviewId(Long.parseLong(id));
						//							repaintinglistDto.setReleasetime(reviewPainting.getReleasetime());
						//							repaintinglistDto.setChangepaintingURL(reviewPainting.getChangepaintingURL());
						//							repaintinglistDto.setNotchangedURL(reviewPainting.getNotchangedURL());
						//							repaintinglistDto.setIntroduce(reviewPainting.getIntroduce());
						ReviewPainting reviewPainting=reviewPaintingService.queryUnique(reviewPaintingQo);
						SysProperties sysProperties=SysProperties.getInstance();
						String imagePath=sysProperties.get("imagePath");
						if(reviewPainting.getTeacher()!=null) {
							reviewPainting.getTeacher().setAvatar(imagePath+"/picture/"+reviewPainting.getTeacher().getAvatar());
						}
						if(StringUtils.isNotEmpty(reviewPainting.getChangepaintingURL())){
							reviewPainting.setChangepaintingURL(imagePath+"/reviewPainting/"+reviewPainting.getChangepaintingURL());
						}	
						if(StringUtils.isNotEmpty(reviewPainting.getNotchangedURL())){
							reviewPainting.setNotchangedURL(imagePath+"/reviewPainting/"+reviewPainting.getNotchangedURL());
						}
						resMap.put("code", "200");
						resMap.put("message", reviewPainting);
						return JSONObject.fromObject(resMap).toString();
					}

				}
			}


		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			resMap.put("code", "500");
			resMap.put("message", "异常抛出！");
			return JSONObject.fromObject(resMap).toString();
		}

	}

	//我的改画
	@ResponseBody
	@RequestMapping("/pingshen")
	public String pingshen(HttpServletRequest request, HttpServletResponse response, Model model,String  status,
			@RequestParam(value="token", required=true)String  token, String type,@RequestParam(value = "page", defaultValue = "1")Integer page) {
		Map<String, Object> resMap=new HashMap<String, Object>();
		reviewPaintingResultDto reviewPaintingResultDto=new reviewPaintingResultDto();
		try {
			AdminSessionQo adminSessionQo=new AdminSessionQo();
			adminSessionQo.setToken(token);
			AdminSession adminSession=adminSessionService.queryUnique(adminSessionQo);
			if(adminSession==null) {
				resMap.put("code", "406");
				resMap.put("message", "不存在此账号！");
				return JSONObject.fromObject(resMap).toString();
			}else {
				UserQo userQo=new UserQo();
				userQo.setUserName(adminSession.getLoginName());
				User user= userService.queryUnique(userQo);
				if(user==null) {
					resMap.put("code", "406");
					resMap.put("message", "未登录!");
					return JSONObject.fromObject(resMap).toString();
				}else {
					System.out.println(user.getUserName());
					//老师素描/速写.../
					//					TeachersQo teachersQo=new TeachersQo();
					//					teachersQo.setUserId(user.getId());
					//					Teacher teacher= teachersService.queryUnique(teachersQo);
					SimpleDateFormat format1=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
					//					if(teacher!=null) {
					//						ReviewPaintingQo reviewPaintingQo=new ReviewPaintingQo();
					//						reviewPaintingQo.setTeacherId(teacher.getId());
					//						reviewPaintingQo.setSeachTeacher(true);
					//						reviewPaintingQo.setSeachUser(true);
					//						reviewPaintingQo.setStatus(Integer.parseInt(status));
					//						reviewPaintingQo.setTypeOne(Long.parseLong(type));
					//						Pagination pagination = new Pagination();
					//						pagination.setPageSize(10);
					//						pagination.setPageNo(page);
					//						pagination.setCondition(reviewPaintingQo);
					//						pagination = reviewPaintingService.queryPagination(pagination);
					//						List<ReviewPainting> reviewPaintingList=(List<ReviewPainting>)pagination.getList();
					//						SysProperties sysProperties=SysProperties.getInstance();
					//						String imagePath=sysProperties.get("imagePath");
					//						for(ReviewPainting reviewPainting:reviewPaintingList) {
					//							reviewPainting.setReleasedate(format1.format(reviewPainting.getReleasetime()));
					//							if(StringUtils.isNotEmpty(reviewPainting.getChangepaintingURL())){
					//								reviewPainting.setChangepaintingURL(imagePath+"/reviewPainting/"+reviewPainting.getChangepaintingURL());
					//							}
					//							StudentQo qo=new StudentQo();
					//							qo.setSeachStudent(true);
					//							qo.setUserid(reviewPainting.getUser().getId());
					//							Student student= studentService.queryUnique(qo);
					//							if(student!=null) {
					//								if(!StringUtils.isEmpty(student.getAvatar())) {
					//									if(student.getAvatar().indexOf(imagePath+"/picture/")>=0) {
					//
					//									}else {
					//										student.setAvatar(imagePath+"/picture/"+student.getAvatar());
					//										reviewPainting.setAvatar(student.getAvatar());
					//									}
					//								}
					//							}else {
					//								TeachersQo teachersQo1=new TeachersQo();
					//								teachersQo1.setSeachUser(true);
					//								teachersQo1.setSeachOrganization(true);
					//								teachersQo1.setUserId(reviewPainting.getUser().getId());
					//								Teacher teacher1= teachersService.queryUnique(teachersQo1);
					//								if(StringUtils.isEmpty(teacher1.getAvatar())) {
					//									if(teacher1.getAvatar().indexOf(imagePath+"/picture/")>=0) {
					//
					//									}else {
					//										teacher1.setAvatar(imagePath+"/picture/"+teacher1.getAvatar());
					//										reviewPainting.setAvatar(teacher1.getAvatar());
					//									}
					//								}
					//							}
					//							if(StringUtils.isNotEmpty(reviewPainting.getNotchangedURL())){
					//								reviewPainting.setNotchangedURL(imagePath+"/reviewPainting/"+reviewPainting.getNotchangedURL());
					//							}
					//							UserQo userQo1=new UserQo();
					//							userQo1.setUserId(reviewPainting.getUser().getId());
					//							userQo1.setSeachRole(true);
					//							User user1=userService.queryUnique(userQo1);
					//							reviewPainting.getUser().setId(user1.getId());
					//
					//						}
					//						reviewPaintingResultDto.setTotalPage(pagination.getTotalPage());
					//						reviewPaintingResultDto.setReviewPaintinglist(reviewPaintingList);
					//						reviewPaintingResultDto.setIsRole(2);
					//						resMap.put("code", "200");
					//						resMap.put("message", reviewPaintingResultDto);
					//						return JSONObject.fromObject(resMap).toString();
					//					}
					//学生素描 速写.../
					if(user!=null) {
						ReviewPaintingQo reviewPaintingQo=new ReviewPaintingQo();
						reviewPaintingQo.setSeachUser(true);
						reviewPaintingQo.setUserId(user.getId());
						reviewPaintingQo.setSeachTeacher(true);
						if(status==null) {

						}else {
							reviewPaintingQo.setStatus(Integer.parseInt(status));
						}

						reviewPaintingQo.setTypeOne(Long.parseLong(type));
						Pagination pagination = new Pagination();
						pagination.setPageSize(10);
						pagination.setCondition(reviewPaintingQo);
						pagination.setPageNo(page);
						pagination = reviewPaintingService.queryPagination(pagination);
						List<ReviewPainting> reviewPaintingList=(List<ReviewPainting>)pagination.getList();
						SysProperties sysProperties=SysProperties.getInstance();
						String imagePath=sysProperties.get("imagePath");
						for(ReviewPainting reviewPainting:reviewPaintingList) {
							reviewPainting.setReleasedate(format1.format(reviewPainting.getReleasetime()));
							if(StringUtils.isNotEmpty(reviewPainting.getVoiceReview())){
								reviewPainting.setVoiceReview(imagePath+"/voice/"+reviewPainting.getVoiceReview());
							}
							if(StringUtils.isNotEmpty(reviewPainting.getChangepaintingURL())){
								reviewPainting.setChangepaintingURL(imagePath+"/reviewPainting/"+reviewPainting.getChangepaintingURL());
							}
							if(reviewPainting.getTeacher()!=null&&StringUtils.isNotEmpty(reviewPainting.getTeacher().getAvatar())) {
								if(reviewPainting.getTeacher().getAvatar().indexOf(imagePath+"/picture/")>=0) {

								}else {
									reviewPainting.getTeacher().setAvatar(imagePath+"/picture/"+reviewPainting.getTeacher().getAvatar());
								}

							}
							if(StringUtils.isNotEmpty(reviewPainting.getNotchangedURL())){
								reviewPainting.setNotchangedURL(imagePath+"/reviewPainting/"+reviewPainting.getNotchangedURL());
							}
							TeachersQo teachersQo1=new TeachersQo();
							teachersQo1.setTeacherId(reviewPainting.getTeacher().getId());
							teachersQo1.setSeachUser(true);
							Teacher teacher1=teachersService.queryUnique(teachersQo1);
							reviewPainting.getTeacher().setUserId(teacher1.getUser().getId());

						}
						reviewPaintingResultDto.setTotalPage(pagination.getTotalPage());
						reviewPaintingResultDto.setReviewPaintinglist(reviewPaintingList);
						reviewPaintingResultDto.setIsRole(1);
						resMap.put("code", "200");
						resMap.put("message", reviewPaintingResultDto);
						return JSONObject.fromObject(resMap).toString();
					}
				}
			}
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			resMap.put("code", "500");
			resMap.put("message", "异常抛出！");
			return JSONObject.fromObject(resMap).toString();
		}
		resMap.put("code", "500");
		resMap.put("message", "查看失败！");
		return JSONObject.fromObject(resMap).toString();
	}

	//查看个人信息
	@ResponseBody
	@RequestMapping("/Personal_information")
	public String Personalinformation(HttpServletRequest request, HttpServletResponse response, Model model,
			@RequestParam(value="token", required=true)String  token) {
		Map<String, Object> resMap=new HashMap<String, Object>();
		PersonalinformationDto personalinformationDto=new PersonalinformationDto();

		try {
			AdminSessionQo adminSessionQo=new AdminSessionQo();
			adminSessionQo.setToken(token);
			AdminSession adminSession=adminSessionService.queryUnique(adminSessionQo);
			if(adminSession==null) {
				resMap.put("code", "406");
				resMap.put("message", "不存在此账号！");
				return JSONObject.fromObject(resMap).toString();
			}else {
				UserQo userQo=new UserQo();
				userQo.setUserName(adminSession.getLoginName());
				User user= userService.queryUnique(userQo);
				if(user==null) {
					resMap.put("code", "406");
					resMap.put("message", "未登录!");
					return JSONObject.fromObject(resMap).toString();
				}else {
					//老师个人信息
					System.out.println(user.getUserName());
					TeachersQo teachersQo=new TeachersQo();
					teachersQo.setUserId(user.getId());
					Teacher teacher= teachersService.queryUnique(teachersQo);
					if(teacher!=null) {
						Map<String ,String>address=new HashMap<String, String>();
						//省
						if(user.getProvince()!=null) {
							Cnnojd province= cnnojdService.get(user.getProvince());
							address.put("Province", province.getId()+province.getName());
						}else {
							address.put("Province", "");
						}
						//市
						if(user.getCity()!=null) {
							Cnnojd Addresscity= cnnojdService.get(user.getCity());
							address.put("City", Addresscity.getId()+Addresscity.getpName());
						}else {
							address.put("City", "");
						}

						//区
						if(user.getCounty()!=null) {
							Cnnojd County= cnnojdService.get(user.getCounty());
							address.put("County", County.getId()+County.getpName());
						}else {
							address.put("County", "");
						}
						SysProperties sysProperties=SysProperties.getInstance();
						String imagePath=sysProperties.get("imagePath");
						personalinformationDto.setAvatar(imagePath+"/picture/"+teacher.getAvatar());
						personalinformationDto.setNickname(teacher.getNickname());
						personalinformationDto.setGender(teacher.getGender());
						personalinformationDto.setPhonenumber(teacher.getPhoneNumber());
						personalinformationDto.setIdentity(null);
						personalinformationDto.setIdentitytag(null);
						personalinformationDto.setTheirprofession(teacher.getTheirprofession());
						personalinformationDto.setAddress(JSONObject.fromObject(address).toString());
						personalinformationDto.setSelfintroduction(user.getSelfintroduction());
						resMap.put("code", "200");
						resMap.put("message",personalinformationDto );
						return JSONObject.fromObject(resMap).toString();
					}
					//学生个人信息
					StudentQo studentQo=new StudentQo(); 
					studentQo.setUserid(user.getId());
					Student student=studentService.queryUnique(studentQo);
					if(student!=null) {
						Map<String ,String>address=new HashMap<String, String>();
						//省
						if(user.getProvince()!=null) {
							Cnnojd province= cnnojdService.get(user.getProvince());
							address.put("Province", province.getId()+province.getName());
						}else {
							address.put("Province", "");
						}

						//市
						if(user.getCity()!=null) {
							Cnnojd Addresscity= cnnojdService.get(user.getCity());
							address.put("City", Addresscity.getId()+Addresscity.getpName());
						}else {
							address.put("City", "");
						}

						//区
						if(user.getCounty()!=null) {
							Cnnojd County= cnnojdService.get(user.getCounty());
							address.put("County", County.getId()+County.getpName());
						}else {
							address.put("County", "");
						}
						SysProperties sysProperties=SysProperties.getInstance();
						String imagePath=sysProperties.get("imagePath");
						personalinformationDto.setAvatar(imagePath+"/picture/"+student.getAvatar());
						personalinformationDto.setNickname(student.getNickname());
						personalinformationDto.setGender(student.getGender());
						personalinformationDto.setPhonenumber(student.getPhonenumber());
						personalinformationDto.setIdentity(Integer.parseInt(student.getIdentity()==null?"0":student.getIdentity()));
						personalinformationDto.setTheirprofession(student.getTheirprofession());
						personalinformationDto.setAddress(JSONObject.fromObject(address).toString());
						personalinformationDto.setSelfintroduction(user.getSelfintroduction());
						personalinformationDto.setSelfintroduction(user.getSelfintroduction());
						resMap.put("code", "200");
						resMap.put("message",personalinformationDto);
						return JSONObject.fromObject(resMap).toString();
					}
				}
			}
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			resMap.put("code", "500");
			resMap.put("message", "异常抛出！");
			return JSONObject.fromObject(resMap).toString();
		}
		resMap.put("code", "500");
		resMap.put("message", "加载个人信息失败！");
		return JSONObject.fromObject(resMap).toString();
	}

	//修改个人信息
	@ResponseBody
	@RequestMapping("/save")
	public String save(HttpServletRequest request, HttpServletResponse response, Model model,
			@RequestParam(value="token", required=true)String  token,PersonalinformationQo qo ) {
		Map<String, Object> resMap=new HashMap<String, Object>();
		MultipartFile pic = null;
		boolean isMultipart = ServletFileUpload.isMultipartContent(request);
		if (isMultipart){ 
			MultipartHttpServletRequest multipartRequest = WebUtils.getNativeRequest(request, MultipartHttpServletRequest.class);
			pic = multipartRequest.getFile("pic");
		}
		try {
			AdminSessionQo adminSessionQo=new AdminSessionQo();
			adminSessionQo.setToken(token);
			AdminSession adminSession=adminSessionService.queryUnique(adminSessionQo);
			if(adminSession==null) {
				resMap.put("code", "406");
				resMap.put("message", "不存在此账号！");
				return JSONObject.fromObject(resMap).toString();
			}else {
				adminSession.getLoginName();
				UserQo userQo=new UserQo();
				userQo.setUserName(adminSession.getLoginName());
				User user= userService.queryUnique(userQo);
				if(user==null) {
					resMap.put("code", "406");
					resMap.put("message", "未登录!");
					return JSONObject.fromObject(resMap).toString();
				}else {
					System.out.println(user.getUserName());
					//老师个人信息保存
					TeachersQo teachersQo=new TeachersQo();
					teachersQo.setUserId(user.getId());
					Teacher teacher= teachersService.queryUnique(teachersQo);

					//学生个人信息保存
					StudentQo studentQo=new StudentQo(); 
					studentQo.setUserid(user.getId());
					Student student=studentService.queryUnique(studentQo);

					if(student!=null||teacher!=null) {
						qo.setUserId(user.getId());
						if(pic==null) {
							qo.setAvatar(null);
						}else {
							SysProperties sysProperties=SysProperties.getInstance();
							String imgPath=sysProperties.get("profilepicture");
							if(teacher!=null) {
								String imge =imgPath+teacher.getAvatar();
								File dest = new File(imge);
								// 路径为图片文件且不为空则进行删除  
								if (dest.isFile() && dest.exists()) {  
									dest.delete();  
								}
							}
							if(student!=null) {
								String imge =imgPath+student.getAvatar();
								File dest = new File(imge);
								// 路径为图片文件且不为空则进行删除  
								if (dest.isFile() && dest.exists()) {  
									dest.delete();  
								}
							}
							int returnTag = -1;
							// 获取图片原始文件名
							String originalFilename = pic.getOriginalFilename();
							System.out.println(originalFilename);
							//文件名使用当前时间
							String name = new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date());
							// 获取上传图片的扩展名(jpg/png/...)
							String extension = FilenameUtils.getExtension(originalFilename);
							String[] regular = { "JPG", "GIF","PNG","JPEG" ,"BMP"};
							boolean flag1 = false;
							// 判断文件格式是否合法
							for (String str : regular) {
								if (extension.equalsIgnoreCase(str)) {
									flag1 = true;
								}
							}
							if (!flag1) {
								returnTag = 0;
								resMap.put("code", "500");
								resMap.put("message", "上传图片格式不正确！");
								return JSONObject.fromObject(resMap).toString();
							}
							// 图片上传的相对路径（因为相对路径放到页面上就可以显示图片）
							String path =imgPath+user.getId()+"/" + name + "." + extension;
							//图片上传的绝对路径
							File dir = new File(path);
							if (!dir.exists()) {
								dir.mkdirs();
							}
							qo.setAvatar(user.getId()+"/" + name + "." + extension);
							pic.transferTo(new File(path));
						}

					}
					if(teacher!=null) {
						ServiceResultDto stu= teachersService.Updateinformation(qo);
						resMap.put("code", "200");
						resMap.put("message","保存成功！");
						return JSONObject.fromObject(resMap).toString();
					}

					if(student!=null) {
						ServiceResultDto stu= studentService.Updateinformation(qo);
						resMap.put("code", "200");
						resMap.put("message","保存成功！");
						return JSONObject.fromObject(resMap).toString();
					}
				}
			}
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			resMap.put("code", "500");
			resMap.put("message", "异常抛出！");
			return JSONObject.fromObject(resMap).toString();
		}
		resMap.put("code", "500");
		resMap.put("message", "保存个人信息失败！");
		return JSONObject.fromObject(resMap).toString();
	}

	//三级联动
	@ResponseBody
	@RequestMapping("/Three_level_linkage")
	public String Threelevellinkage(String pid) {
		Map<String, Object> resMap=new HashMap<String, Object>();
		if(StringUtils.isEmpty(pid)) {
			CnnojdQo qo=new CnnojdQo();
			qo.setpId(0L);
			List<Cnnojd>  cnnojd=cnnojdService.queryList(qo);
			resMap.put("code", "200");
			resMap.put("message", cnnojd);
			return JSONObject.fromObject(resMap).toString();
		}else {
			CnnojdQo qo=new CnnojdQo();
			qo.setpId(Long.parseLong(pid));
			List<Cnnojd>  cnnojd=cnnojdService.queryList(qo);
			resMap.put("code", "200");
			resMap.put("message", cnnojd);
			return JSONObject.fromObject(resMap).toString();
		}
	}
	/**
	 * 查看昵称是否存在
	 * @param token
	 * @param nickName
	 * @return
	 */
	@RequestMapping("/queryNickname")
	@ResponseBody
	public String queryNickname(@RequestParam(value="token", required=true)String  token,String nickName) {
		Map<String, Object> resMap=new HashMap<String, Object>();
		try {
			AdminSessionQo adminSessionQo=new AdminSessionQo();
			adminSessionQo.setToken(token);
			AdminSession adminSession=adminSessionService.queryUnique(adminSessionQo);
			if(adminSession==null) {
				resMap.put("code", "406");
				resMap.put("message", "不存在此账号！");
				return JSONObject.fromObject(resMap).toString();
			}else {
				UserQo userQo=new UserQo();
				userQo.setUserName(adminSession.getLoginName());
				User user= userService.queryUnique(userQo);
				if(user==null) {
					resMap.put("code", "406");
					resMap.put("message", "未登录!");
					return JSONObject.fromObject(resMap).toString();
				}else {
					//老师个人信息
					System.out.println(user.getUserName());
					TeachersQo teachersQo=new TeachersQo();
					teachersQo.setUserId(user.getId());
					Teacher teacher= teachersService.queryUnique(teachersQo);
					StudentQo studentQo=new StudentQo();
					studentQo.setUserid(user.getId());
					Student student= studentService.queryUnique(studentQo);
					if(teacher!=null) {
						TeachersQo teachersQo2=new TeachersQo();
						teachersQo2.setNickname(nickName);
						Teacher teacher2= teachersService.queryUnique(teachersQo2);
						if(teacher2!=null) {
							resMap.put("code", "500");
							resMap.put("message", "此昵称已被占用！");
							return JSONObject.fromObject(resMap).toString();
						}else {
							resMap.put("code", "200");
							resMap.put("message", "此昵称可用！");
							return JSONObject.fromObject(resMap).toString();
						}
					}else if(student!=null) {
						StudentQo studentQo2=new StudentQo();
						studentQo2.setNickName(nickName);
						Student student2= studentService.queryUnique(studentQo2);
						if(student2!=null) {
							resMap.put("code", "500");
							resMap.put("message", "此昵称已被占用！");
							return JSONObject.fromObject(resMap).toString();
						}else {
							resMap.put("code", "200");
							resMap.put("message", "此昵称可用！");
							return JSONObject.fromObject(resMap).toString();
						}
					}else {
						resMap.put("code", "406");
						resMap.put("message", "没有找到此账号！");
						return JSONObject.fromObject(resMap).toString();
					}
				}
			}

		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			resMap.put("code", "500");
			resMap.put("message", "系统异常！");
			return JSONObject.fromObject(resMap).toString();
		}
	}

	//我的改画
	@ResponseBody
	@RequestMapping("/teacher_Pingshen")
	public String teacher_Pingshen(HttpServletRequest request, HttpServletResponse response, Model model,String  status,
			@RequestParam(value="token", required=true)String  token, String type,@RequestParam(value = "page", defaultValue = "1")Integer page) {
		Map<String, Object> resMap=new HashMap<String, Object>();
		reviewPaintingResultDto reviewPaintingResultDto=new reviewPaintingResultDto();
		try {
			AdminSessionQo adminSessionQo=new AdminSessionQo();
			adminSessionQo.setToken(token);
			AdminSession adminSession=adminSessionService.queryUnique(adminSessionQo);
			if(adminSession==null) {
				resMap.put("code", "406");
				resMap.put("message", "不存在此账号！");
				return JSONObject.fromObject(resMap).toString();
			}else {
				UserQo userQo=new UserQo();
				userQo.setUserName(adminSession.getLoginName());
				User user= userService.queryUnique(userQo);
				if(user==null) {
					resMap.put("code", "406");
					resMap.put("message", "未登录!");
					return JSONObject.fromObject(resMap).toString();
				}else {
					System.out.println(user.getUserName());
					//老师素描/速写.../
					TeachersQo teachersQo=new TeachersQo();
					teachersQo.setUserId(user.getId());
					Teacher teacher= teachersService.queryUnique(teachersQo);
					SimpleDateFormat format1=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
					if(teacher!=null) {
						ReviewPaintingQo reviewPaintingQo=new ReviewPaintingQo();
						reviewPaintingQo.setTeacherId(teacher.getId());
						reviewPaintingQo.setSeachTeacher(true);
						reviewPaintingQo.setSeachUser(true);
						reviewPaintingQo.setStatus(Integer.parseInt(status));
						reviewPaintingQo.setTypeOne(Long.parseLong(type));
						Pagination pagination = new Pagination();
						pagination.setPageSize(10);
						pagination.setPageNo(page);
						pagination.setCondition(reviewPaintingQo);
						pagination = reviewPaintingService.queryPagination(pagination);
						List<ReviewPainting> reviewPaintingList=(List<ReviewPainting>)pagination.getList();
						SysProperties sysProperties=SysProperties.getInstance();
						String imagePath=sysProperties.get("imagePath");
						for(ReviewPainting reviewPainting:reviewPaintingList) {
							reviewPainting.setReleasedate(format1.format(reviewPainting.getReleasetime()));
							if(StringUtils.isNotEmpty(reviewPainting.getChangepaintingURL())){
								reviewPainting.setChangepaintingURL(imagePath+"/reviewPainting/"+reviewPainting.getChangepaintingURL());
							}
							if(StringUtils.isNotEmpty(reviewPainting.getVoiceReview())){
								reviewPainting.setVoiceReview(imagePath+"/voice/"+reviewPainting.getVoiceReview());
							}
							if(reviewPainting.getUser().getIsRole()==2 ) {
								StudentQo qo=new StudentQo();
								qo.setSeachStudent(true);
								qo.setUserid(reviewPainting.getUser().getId());
								Student student= studentService.queryUnique(qo);
								reviewPainting.getUser().setNickName(student.getNickname());
								if(student!=null) {
									if(!StringUtils.isEmpty(student.getAvatar())) {
										if(StringUtils.isEmpty(reviewPainting.getUser().getAvatar())) {
											student.setAvatar(imagePath+"/picture/"+student.getAvatar());
											reviewPainting.getUser().setAvatar(student.getAvatar());
										}else {
											if(reviewPainting.getUser().getAvatar().indexOf(imagePath+"/picture/")>=0) {

											}else {
												student.setAvatar(imagePath+"/picture/"+student.getAvatar());
												reviewPainting.getUser().setAvatar(student.getAvatar());

											}
										}
									}
								}
							}else {
								TeachersQo teachersQo1=new TeachersQo();
								teachersQo1.setSeachUser(true);
								teachersQo1.setSeachOrganization(true);
								teachersQo1.setUserId(reviewPainting.getUser().getId());
								Teacher teacher1= teachersService.queryUnique(teachersQo1);
								reviewPainting.getUser().setNickName(teacher1.getNickname());
								if(!StringUtils.isEmpty(teacher1.getAvatar())) {
									if(StringUtils.isEmpty(reviewPainting.getUser().getAvatar())) {
										teacher1.setAvatar(imagePath+"/picture/"+teacher1.getAvatar());
										reviewPainting.getUser().setAvatar(teacher1.getAvatar());
									}else {
										if(reviewPainting.getUser().getAvatar().indexOf(imagePath+"/picture/")>=0) {

										}else {
											teacher1.setAvatar(imagePath+"/picture/"+teacher1.getAvatar());
											reviewPainting.getUser().setAvatar(teacher1.getAvatar());
										}
									}
								}
							}
							if(StringUtils.isNotEmpty(reviewPainting.getNotchangedURL())){
								reviewPainting.setNotchangedURL(imagePath+"/reviewPainting/"+reviewPainting.getNotchangedURL());
							}
							UserQo userQo1=new UserQo();
							userQo1.setUserId(reviewPainting.getUser().getId());
							userQo1.setSeachRole(true);
							User user1=userService.queryUnique(userQo1);
							reviewPainting.getUser().setId(user1.getId());

						}
						reviewPaintingResultDto.setTotalPage(pagination.getTotalPage());
						reviewPaintingResultDto.setReviewPaintinglist(reviewPaintingList);
						reviewPaintingResultDto.setIsRole(2);
						resMap.put("code", "200");
						resMap.put("message", reviewPaintingResultDto);
						return JSONObject.fromObject(resMap).toString();
					}else {
						resMap.put("code", "500");
						resMap.put("message", "不存在此老师!!");
						return JSONObject.fromObject(resMap).toString();
					}
					//学生素描 速写.../
					//						UserQo userQo2=new UserQo(); 
					//						userQo2.setUserId(user.getId());
					//						User user2=userService.queryUnique(userQo2);
					//						if(user2!=null) {
					//							ReviewPaintingQo reviewPaintingQo=new ReviewPaintingQo();
					//							reviewPaintingQo.setSeachUser(true);
					//							reviewPaintingQo.setUserId(user2.getId());
					//							reviewPaintingQo.setSeachTeacher(true);
					//							if(status==null) {
					//
					//							}else {
					//								reviewPaintingQo.setStatus(Integer.parseInt(status));
					//							}
					//
					//							reviewPaintingQo.setTypeOne(Long.parseLong(type));
					//							Pagination pagination = new Pagination();
					//							pagination.setPageSize(10);
					//							pagination.setCondition(reviewPaintingQo);
					//							pagination.setPageNo(page);
					//							pagination = reviewPaintingService.queryPagination(pagination);
					//							List<ReviewPainting> reviewPaintingList=(List<ReviewPainting>)pagination.getList();
					//							SysProperties sysProperties=SysProperties.getInstance();
					//							String imagePath=sysProperties.get("imagePath");
					//							for(ReviewPainting reviewPainting:reviewPaintingList) {
					//								reviewPainting.setReleasedate(format1.format(reviewPainting.getReleasetime()));
					//								if(StringUtils.isNotEmpty(reviewPainting.getChangepaintingURL())){
					//									reviewPainting.setChangepaintingURL(imagePath+"/reviewPainting/"+reviewPainting.getChangepaintingURL());
					//								}
					//								if(reviewPainting.getTeacher()!=null&&StringUtils.isNotEmpty(reviewPainting.getTeacher().getAvatar())) {
					//									if(reviewPainting.getTeacher().getAvatar().indexOf(imagePath+"/picture/")>=0) {
					//
					//									}else {
					//										reviewPainting.getTeacher().setAvatar(imagePath+"/picture/"+reviewPainting.getTeacher().getAvatar());
					//									}
					//
					//								}
					//								if(StringUtils.isNotEmpty(reviewPainting.getNotchangedURL())){
					//									reviewPainting.setNotchangedURL(imagePath+"/reviewPainting/"+reviewPainting.getNotchangedURL());
					//								}
					//								TeachersQo teachersQo1=new TeachersQo();
					//								teachersQo1.setTeacherId(reviewPainting.getTeacher().getId());
					//								teachersQo1.setSeachUser(true);
					//								Teacher teacher1=teachersService.queryUnique(teachersQo1);
					//								reviewPainting.getTeacher().setUserId(teacher1.getUser().getId());
					//
					//							}
					//							reviewPaintingResultDto.setTotalPage(pagination.getTotalPage());
					//							reviewPaintingResultDto.setReviewPaintinglist(reviewPaintingList);
					//							reviewPaintingResultDto.setIsRole(1);
					//							resMap.put("code", "200");
					//							resMap.put("message", reviewPaintingResultDto);
					//							return JSONObject.fromObject(resMap).toString();
					//						}
				}
			}
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			resMap.put("code", "500");
			resMap.put("message", "异常抛出！");
			return JSONObject.fromObject(resMap).toString();
		}
	}
}


